package com.atguigu.gmall.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.atguigu.gmall.product.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/10/29 23:14
 */
@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    private ManagerService managerService;

    @Autowired
    private BaseTradeMarkService baseTradeMarkService;


    /**
     * 根据品牌id获取品牌信息
     * /api/product/inner/getTrademark/{tmId}
     * @param tmId
     * @return
     */
    @GetMapping("/inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable("tmId") Long tmId) {
        return baseTradeMarkService.getById(tmId);
    }

    /**
     * 获取首页分类数据
     * /api/product/getBaseCategoryList
     * getBaseCategoryList
     * @return
     */
    @GetMapping("/getBaseCategoryList")
    public Result getBaseCategoryList() {
        List<JSONObject> resultList = managerService.getBaseCategoryList();
        return Result.ok(resultList);
    }

    /**
     * 根据skuId获取SkuInfo
     * /api/product/inner/getSkuInfo/{skuId}
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return managerService.getSkuInfo(skuId);
    }


    /**
     * 根据sku_id查询三级分类
     * /api/product/inner/getCategoryView/{category3Id}
     * @param category3Id
     * @return
     */
    @GetMapping("/inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id) {
        return managerService.getCategoryView(category3Id);
    }


    /**
     * 根据skuid查询最新实时价格
     * /api/product/inner/getSkuPrice/{skuId}
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId")Long skuId) {
        return managerService.getSkuPrice(skuId);
    }


    /**
     * 根据spuId,skuId 获取销售属性数据以及选中状态
     * /api/product/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}
     * @param skuId
     * @param spuId
     * @return
     */
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable("skuId")Long skuId,
                                                          @PathVariable("spuId") Long spuId) {
        return managerService.getSpuSaleAttrListCheckBySku(skuId, spuId);
    }


    /**
     * 根据spuId 获取到销售属性值Id 与skuId 组成的数据集 -- 选取不同的销售属性值组合后 找到对应的sku
     * /api/product/inner/getSkuValueIdsMap/{spuId}
     * @param spuId
     * @return
     */
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId")Long spuId) {
        return managerService.getSkuValueIdsMap(spuId);
    }


    /**
     * 根据spuid查询海报集合信息
     * /api/product/inner/findSpuPosterBySpuId/{spuId}
     * @param spuId
     * @return
     */
    @GetMapping("/inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable("spuId") Long spuId) {
        return managerService.findSpuPosterBySpuId(spuId);
    }


    /**
     * 根据skuId 获取平台属性数据
     * /api/product/inner/getAttrList/{skuId}
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId")Long skuId) {
        return managerService.getAttrList(skuId);
    }


}
